﻿using System;
using System.IO;
using System.Windows.Forms;

namespace SimpleMediaManager
{
    static class Program
    {
        public const string TMDB_API_KEY = "756ba311ba48c9f4c90f719078533f62";
        public const string OSDB_USERNAME = "";
        public const string OSDB_PASSWORD = "";
        public const string SETTINGS_FILE = "settings.xml";
        public const string DATABASE_FILE = "database.xml";

        public static TMDB.Api Tmdb;
        public static OSDB.Api Osdb;
        public static Settings Settings;
        public static Database Database;

        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                Program.Tmdb = new TMDB.Api(TMDB_API_KEY);
                Program.Osdb = new OSDB.Api(OSDB_USERNAME, OSDB_PASSWORD);

                if (!File.Exists(SETTINGS_FILE))
                {
                    Program.Settings = new Settings();
                    Program.Settings.Serialize(SETTINGS_FILE);
                }
                else
                {
                    Program.Settings = Settings.Deserialize(SETTINGS_FILE);
                }

                if (!File.Exists(DATABASE_FILE))
                {
                    Program.Database = new Database();
                }
                else
                {
                    Program.Database = Database.Deserialize(DATABASE_FILE);
                }

                Application.Run(new Main());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message + Environment.NewLine + Application.ProductName + " will now exit.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
        }
    }
}
